package cn.kt.mywxdemo.message;

import cn.kt.mywxdemo.token.TokenUtil;
import cn.kt.mywxdemo.utils.HttpUtil;
import org.junit.Test;

/**
 * 测试 素材管理
 * <p>
 * Created by tao.
 * Date: 2023/3/7 19:56
 * 描述:
 */
public class TestMedia {

    //上传临时素材
    @Test
    public void testImage() {
        String url = String.format("https://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s",
                TokenUtil.getAccessToken(),
                "image");
        String result = HttpUtil.doPostByFile(url, null, "D:/images/bg.png", "");
        System.out.println(result);
        //{"type":"image","media_id":"h7mvkpNYOsmyPtPxnvwh7hopFlQ2LLBalyiCXcfGG2p943IqKHrrSTYdIDMbeRID","created_at":1670224505,"item":[]}
    }

    /*
    https://api.weixin.qq.com/cgi-bin/media/get?access_token=66_0qO7imNJGvzK1_oSoEK461VzV9406hIL8nv0GEJLH4okCZoYGR1c4uaQDrWdVsbB2fccXTEOac4kOg4eVdyZhp4Umjsl3RMqeoRv8BwTdj-x53ro9Dkf01L4pXMOVKeABAFMB&media_id=WLZtwg8LEjKZstdxRKVGfK8cX0ctJp4rIt4wVgkx2HvTHRfF1vdG8Tlqg3ilJN6P
     */

    //获得临时素材
    @Test
    public void testGetImage() {
        String mediaId = "WLZtwg8LEjKZstdxRKVGfHvkYJz4XlKeE9XH_zl7bkIjg49oH7JnCJNsMqJYlCTx";
        String url = String.format("https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s",
                TokenUtil.getAccessToken(),
                mediaId);
        String result = HttpUtil.doGet(url);
        System.out.println(result);

    }
}
